#include <bits/stdc++.h>

using namespace std;
int t,n,a[1000000],b[1000000],ans;
void check(){
    int cnt=0;
    for(int i=1;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(b[i]==b[j]){
                //cout<<a[i]<<" "<<a[j]<<endl;
                if(a[i]==a[j]) {
                    cnt+=a[i];
                    //cout<<1;
                }
                break;
            }
            else break;
        }
    }
    //for(int i=0;i<n;i++) cout<<b[i]<<" ";
    //cout<<endl;
    ans=max(ans,cnt);
    return;
}
void dfs(int T){
    if(T>=n){
        check();
        return;
    }
    b[T]=0;
    dfs(T+1);
    b[T]=1;
    dfs(T+1);
}
int main(){

    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;
        ans=0;
        memset(b,0,sizeof(b));
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++) cout<<a[i]<<" ";
        dfs(0);
        cout<<ans<<endl;
    }
    return 0;
}
